home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 10
/
aminetcdnumber101996.iso
/
Aminet
/
util
/
misc
/
ICookieRT.lha
/
IntuiCookie for Reqtools
/
IntuiCookie.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-12-17
|
6KB
|
199 lines
#include <libraries/reqtools.h>
#include <graphics/text.h>
#include <clib/icon_protos.h>
#include <stdio.h>
#define ENTSIZE 7L
#define METACHAR '%'
enum icookie_errors {ERR_NONE, ERR_INTUITION, ERR_ICON, ERR_DISKFONT, ERR_REQTOOLS, ERR_NOCOOKIEFILE, ERR_NOHASHFILE, ERR_COOKIEFILE, ERR_HASHFILE, ERR_FSEEK, ERR_NOENTRIES, ERR_NOFONT };
char *errors[] = { "",
"Could not open Intuition.library V37+",
"Could not open Icon.library V37+",
"Could not open Diskfont.library V37+",
"Could not open Reqtools.library",
"No COOKIEFILE tooltype\nUse the Installer script to configure IntuiCookie!",
"No HASHFILE tooltype\nUse the Installer script to configure IntuiCookie!",
"Could not open COOKIEFILE\nCheck if you set the tooltypes correctly.",
"Could not open HASHFILE\nCheck if you set the tooltype correctly.",
"Fatal error: Could not calculate size of hashfile\nThis shouldn't occur :-(",
"Wrong format: Use '%%' as cookie separator\nRefer to the documentation for more information",
"Could not find font\nCheck if you set the tooltypes correctly." };
char *version[] = { "$VER: IntuiCookie for Reqtools 1.0 (17.12.95)", "IntuiCookie for Reqtools 1.0 ©1995 Christian Kemp"};
void fool_DICE( void ) { _waitwbmsg(); }
#define main _main
struct Library * IconBase;
struct DiskfontBase *DiskfontBase;
extern struct Library *IntuitionBase;
struct ReqToolsBase *ReqToolsBase;
struct TextAttr cfont_ta;
struct TextFont *cfont_tt;
struct DiskObject *mydo;
FILE *cookiefile;
FILE *hashfile;
char cookiebuffer[2048];
BYTE *tooltype;
int nentries, oneiwant, c, sawmeta = 0, i = 0, reqpos;;
long cookiepos;
ULONG *seconds, *micros;
/**********/
static void init( void )
{
if (!(IconBase = OpenLibrary("icon.library", 37)))
cleanup(ERR_ICON);
if (!(IntuitionBase = OpenLibrary("intuition.library", 37)))
cleanup(ERR_INTUITION);
if (!(DiskfontBase = OpenLibrary("diskfont.library", 37)))
cleanup(ERR_DISKFONT);
if (!(ReqToolsBase = OpenLibrary("reqtools.library", 38)))
cleanup(ERR_REQTOOLS);
}
/**********/
main()
{
init();
mydo = GetDiskObject("PROGDIR:IntuiCookie");
parse_tooltypes();
get_cookienumber();
while ((c = fgetc(cookiefile)) != EOF && sawmeta < 2)
{
switch ( c )
{
case '\n':
cookiebuffer[i++] = '\n';
break;
case METACHAR:
if ((c = fgetc(cookiefile)) == METACHAR) sawmeta=+2;
else
{
ungetc(c, cookiefile);
cookiebuffer[i++] = '%';
}
break;
case '@':
c = fgetc(cookiefile);
/* switch ( c )
{
default:
cookiebuffer[i++] = c;
break;
} */
break;
case '\t':
strcat(cookiebuffer, " ");
break;
default:
cookiebuffer[i++] = c;
break;
}
}
cookiebuffer[--i] = '\0'; /* Kein unnützes \n am Ende eines Cookie */
ULONG tags[] = { RT_TextAttr, &cfont_ta, RTEZ_ReqTitle, version[1], RT_ReqPos, reqpos, TAG_END };
rtEZRequest ( "%s", "Continue", NULL, (struct TagItem *)tags, cookiebuffer);
cleanup(ERR_NONE);
}
/**********/
cleanup(UBYTE error)
{
if ( mydo ) FreeDiskObject( mydo );
if ( cookiefile ) fclose( cookiefile );
if ( hashfile ) fclose( hashfile );
if ( IconBase ) CloseLibrary ( IconBase );
if ( ReqToolsBase) CloseLibrary ( ReqToolsBase );
if ( DiskfontBase ) CloseLibrary( DiskfontBase );
if (error)
{
struct EasyStruct cookieES = {
sizeof (struct EasyStruct),
0,
"Error",
"%s" ,
"Continue",
};
EasyRequest(NULL,&cookieES,NULL,errors[error]);
}
if (IntuitionBase) CloseLibrary(IntuitionBase);
exit(0);
}
parse_tooltypes()
{
if ((tooltype = FindToolType(mydo->do_ToolTypes, "COOKIEFILE")) == 0) cleanup(ERR_NOCOOKIEFILE);
if ((cookiefile = fopen(tooltype, "r")) == NULL) cleanup(ERR_COOKIEFILE);
if ((tooltype = FindToolType(mydo->do_ToolTypes, "HASHFILE")) == 0) cleanup(ERR_NOHASHFILE);
if ((hashfile = fopen(tooltype, "r")) == NULL) cleanup(ERR_HASHFILE);
if ((tooltype = FindToolType(mydo->do_ToolTypes, "COOKIEFONT")) != 0)
{
cfont_ta.ta_Name = tooltype;
tooltype = FindToolType(mydo->do_ToolTypes, "COOKIEFONTSIZE");
cfont_ta.ta_YSize = atoi(tooltype);
cfont_tt = OpenDiskFont(&cfont_ta);
if (!cfont_tt) cleanup(ERR_NOFONT);
}
if (tooltype = FindToolType(mydo->do_ToolTypes, "REQPOS"));
{
if (MatchToolValue(tooltype,"POINTER") == TRUE) reqpos = REQPOS_POINTER;
if (MatchToolValue(tooltype,"TOPLEFT") == TRUE) reqpos = REQPOS_TOPLEFTSCR;
if (MatchToolValue(tooltype,"CENTER") == TRUE) reqpos = REQPOS_CENTERSCR;
}
}
/***** Get the size of the hashfile, compute a random number and set the
/***** position we will read from according to this data *****/
get_cookienumber()
{
if ( fseek ( hashfile, 0L, SEEK_END) != NULL ) cleanup(ERR_FSEEK);
nentries = ( ftell ( hashfile ) / ENTSIZE) -1;
if (nentries <= 0) cleanup(ERR_NOENTRIES);
CurrentTime( &seconds, µs);
oneiwant = RangeRand(atoi(seconds) + micros) % nentries;
fseek ( hashfile, ( long ) oneiwant * ENTSIZE, SEEK_SET );
fscanf ( hashfile, "%lx", &cookiepos );
fseek ( cookiefile, cookiepos, SEEK_SET);
}